/**
 * (C)2012 Exlu Corporation. All rights reserved.
 * 文件名 : cn.exlu.wea.tpk.test.EmailClient.java
 * 注意事項   :
 */
package cn.exlu.wea.tpk.test;

import java.io.File;
import java.io.UnsupportedEncodingException;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import cn.exlu.wea.tpk.email.EmailConnection;
import cn.exlu.wea.tpk.email.EmailService;
import cn.exlu.wea.tpk.email.EmailTransport;
import cn.exlu.wea.tpk.email.LoginAuthentication;
import cn.exlu.wea.tpk.email.TextEmail;

/**
 * @author Mark 
 * @version 1.0.1
 * 2013-1-27
 * EmailClient.java
 */
public class EmailClient {

    /**
     * @param args
     * @throws MessagingException 
     * @throws UnsupportedEncodingException 
     * @throws AddressException 
     * @throws EmailException 
     */
    public static void main(String[] args) throws MessagingException {
        EmailService service = new EmailService();
        service.setSmtpAddress("smtp.126.com");
        service.setAuth(true);
        LoginAuthentication loginAuth = new LoginAuthentication("testlogin123@126.com",
            "testlogin1");
        TextEmail te = new TextEmail();
        te.setSendFrom("testlogin123@126.com");
        te.setSendTo("mark@yikongxy.com");
        te.setSubject("你好");
        te.setText("Hello this is first text email");
        te.setFile(new File("D:/temp/DB_Data.xls"));
        EmailConnection ec = service.createEmailConnection(loginAuth);
        EmailTransport et = ec.createEmailTransport("smtp");
        et.send(te);
        te.setText("Hello this is second text email");
        et.send(te);
        et.close();
        System.out.println("Success");
    }
}
